/**
 * 
 */
package com.kexinde.wjifen.action;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.RequestAware;

import com.kexinde.wjifen.config.CommonCfg;
import com.kexinde.wjifen.dao.SearchShopDao;
import com.kexinde.wjifen.vo.PageInfo;
import com.kexinde.wjifen.vo.SearchShop;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author vincent
 * 
 */
public class SearchShopAction extends ActionSupport implements RequestAware {

	private final static Logger logger = Logger.getLogger(SearchShopAction.class);
	private Map<String, Object> request;
	private PageInfo pageInfo;
	private String keyWord; // 搜索关键字
	private int listType = 0; // 排序类型，0为默认，1为热门度，2为可兑换商品数量

	/**
	 * 微一下,模糊搜索商家,根据商家名,服务项 此处采用页面级缓存
	 * 
	 * @return
	 */
	public String searchShops() {
		try {
			if (pageInfo == null) {
				pageInfo = new PageInfo(1, CommonCfg.shopsLineSize); // 当前第一页，每页10条记录
			}
			if (keyWord == null) {
				keyWord = "";
			}

			SearchShopDao searchShopDao = new SearchShopDao();

			if (listType == 0) {	//默认排序
				List<SearchShop> defaultSearchShops = searchShopDao
						.searchShopsByDefault(keyWord, pageInfo);
				request.put("searchShops", defaultSearchShops);
			}
			
			if (listType == 1) {	//按商家热门度排序
				List<SearchShop> hotSearchShops = searchShopDao
						.searchShopsByHot(keyWord, pageInfo);
				request.put("searchShops", hotSearchShops);
			}
			
			if (listType == 2) {	//按可兑换商品数量排序
				List<SearchShop> amountSearchShops = searchShopDao
				.searchShopsByAmount(keyWord, pageInfo);
				request.put("searchShops", amountSearchShops);
			}

			

		} catch (Exception e) {
			logger.error(e);
			return ERROR;
		}
		return SUCCESS;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	public PageInfo getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(PageInfo pageInfo) {
		this.pageInfo = pageInfo;
	}

	public String getKeyWord() {
		return keyWord;
	}

	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}

	public int getListType() {
		return listType;
	}

	public void setListType(int listType) {
		this.listType = listType;
	}

}
